package com.day11.test3_jdk8_date;

import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author 小坡
 * @date 2022/9/14  15:57
 **/
public class TestLocalDateTime {
    public static void main(String[] args) {
        method1();


        String s = "2022年12月12日 12:12:12";
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse(s, pattern);
        System.out.println(parse);
        int year = parse.getYear();
        System.out.println("年份为" + year);
        int monthValue = parse.getMonthValue();
        System.out.println("月份为" + monthValue);
        int dayOfMonth = parse.getDayOfMonth();
        System.out.println("这是" + dayOfMonth + "号");
        int dayOfYear = parse.getDayOfYear();
        System.out.println("这是一年中的第" + dayOfYear + "天");
        DayOfWeek dayOfWeek = parse.getDayOfWeek();
        System.out.println("星期为" + dayOfWeek);
        int minute = parse.getMinute();
        System.out.println("分钟为" + minute);
        int hour = parse.getHour();
        System.out.println("小时为" + hour);
    }

    private static void method1() {
        LocalDateTime localDateTime = LocalDateTime.of(2022, 12, 12, 12, 12, 12);
        System.out.println(localDateTime);  //2022-12-12T12:12:12


        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        String s = localDateTime.format(pattern);
        System.out.println(s);
    }
}
